#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


int main()
{
	FILE* fp=fopen("log.txt","a");//追加：
	if(fp==NULL)
	{
		perror("fopen");
		return 1;
	}
	const char* message="hello file";
	int i=0;
	char buffer[1024];
	while(i<5)
	{
		snprintf(buffer,sizeof(buffer),"%s:%d\n",message,i);
		fputs(buffer,fp);
		i++;
	}
	fclose(fp);
	
	return 0;	
}
